<?php
/* SVN FILE: $Id: statistics_team.php 328 2010-07-21 11:00:00Z gregory.rome $ */
/**
 * StatisticsTeam Model.
 *
 * @todo Add file description.
 *
 * cBBweb : Digital Blood Bowl league interface (http://code.google.com/p/cbbweb/)
 * Copyright 2009-2010, Grégory Romé.
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright	 Copyright 2009-2010, Grégory Romé.
 * @link		  http://code.google.com/p/cbbweb/ cBBweb Project
 * @package	   cbbweb
 * @subpackage	cbbweb.models
 * @version	   $Revision: 328 $
 * @modifiedby	$LastChangedBy: gregory.rome $
 * @lastmodified  $Date: 2010-07-21 11:00:00 +0000 (Wed, 21 Jul 2010) $
 * @license	   http://www.opensource.org/licenses/mit-license.php The MIT License
 */

/**
 * StatisticsTeam Model.
 *
 * @todo Add model description.
 *
 * @package	   cbbweb
 * @subpackage	cbbweb.models
 */
class StatisticsTeam extends AppModel {
	var $name = 'StatisticsTeam';
	var $primaryKey = 'ID';

	/**
	 * belongsTo relationship.
	 *
	 * @var array
	 */
	var $belongsTo = array(
		'Team' => array(
			'className' => 'Team',
			'foreignKey' => 'idTeam_Listing',
			'fields' => array('Team.ID', 'Team.strName')));

	/**
	 * Constructor. Binds the model's database table to the object.
	 *
	 * Add virtual fields when calling __construct.
	 *
	 * @param mixed  $id Set this ID for this model on startup, can also be an array of options, see above.
	 * @param string $table Name of database table to use.
	 * @param string $ds DataSource connection name.
	 */
	function __construct($id = false, $table = null, $ds = null) {
		parent::__construct($id, $table, $ds);
		$this->virtualFields = array(
			'iMatch' => sprintf('(%s.iWins+%s.iDraws+%s.iLoss)', $this->alias, $this->alias, $this->alias),
			'fPerWins' => sprintf('100*(%s.iWins / CAST((%s.iWins+%s.iDraws+%s.iLoss) AS REAL))',
					$this->alias, $this->alias, $this->alias, $this->alias),
			'fPerDraws' => sprintf('100*(%s.iDraws / CAST((%s.iWins+%s.iDraws+%s.iLoss) AS REAL))',
					$this->alias, $this->alias, $this->alias, $this->alias),
    	'fPerLoss' => sprintf('100*(%s.iLoss / CAST((%s.iWins+%s.iDraws+%s.iLoss) AS REAL))',
					$this->alias, $this->alias, $this->alias, $this->alias)
		);
	}
}
?>